/*
 * 10.7
 * Design an algorithm to find the kth number such that the only prime factors are 3,
 * 5, and 7.
 */
#include <stdio.h>

const int maxlen = 10000;
char numbers[maxlen];

int search(int k)
{
    const int p[] = { 3, 5, 7 };
    int count = 0;
    int curr = 1;
    do {
        if (count == k) {
            return curr;
        }
        for (int i = 0; i < sizeof(p)/sizeof(p[0]); i++) {
            numbers[curr*p[i]] = 1;
        }
        while (numbers[++curr] == 0) {
        }
        count++;
    } while (true);
    return -1;
}

int main()
{
    int n = search(12);
    printf("%d\n", n);
    return 0;
}
